const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
  entry: './src/index.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [{
          //指定加载器
          loader: 'babel-loader',
          //配置babel
          options: {
            //设置定制环境
            presets: [
              //指定环境插件
              "@babel/preset-env",
              {
                //兼容目标浏览器
                targets: { 'chrome': "88" },
                //corejs版本
                "corejs": "3",
                //使用corejs方式
                "userBuiltIns": "usage"
              }
            ]
          }
        }, 'ts-loader'],
        exclude: '/node_modules/'
      },
    ]
  },
  //配置webpack插件
  plugins: [new HTMLWebpackPlugin({
    template: './src/index.html'
  }), new CleanWebpackPlugin()],

  //设置引用模块
  resolve: {
    extensions: ['.ts', '.js']
  }
}
